package cn.qzzg.service.impl;

import cn.qzzg.common.exceptlion.CommonException;
import cn.qzzg.enums.CodeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.qzzg.pojo.User;
import cn.qzzg.service.UserService;
import cn.qzzg.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
* @author 九九
* @description 针对表【user(用户表)】的数据库操作Service实现
* @createDate 2023-03-25 21:51:39
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{
    /**
     * 通用条件构造器
     */
    private LambdaQueryWrapper<User> wrapper;

    @Override
    public User findById(String objId) {
        if (ObjectUtils.isEmpty(objId))
            throw new CommonException(CodeEnum.USER_ERROR_A0410);
        return getById(objId);
    }

    @Override
    public User findByOpenId(String openId) {
        wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getOpenId, openId);
        if (ObjectUtils.isEmpty(openId))
            throw new CommonException(CodeEnum.USER_ERROR_A0410);
        return getOne(wrapper);
    }

    @Override
    public String saveOne(User saveObj) {
        if (ObjectUtils.isEmpty(saveObj))
            throw new CommonException(CodeEnum.USER_ERROR_A0410);
        save(saveObj);
        return saveObj.getUserId();
    }
}




